#include "i2c_driver.h"
#define I2C_MASTER_NUM              0 
#define I2C_MASTER_FREQ_HZ          100000                     /*!< I2C master clock frequency */
#define I2C_MASTER_TX_BUF_DISABLE   0                          /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_BUF_DISABLE   0                          /*!< I2C master doesn't need buffer */
#define I2C_MASTER_TIMEOUT_MS       1000


static struct i2c_client i2c_client_array[MAX_BUS_NUM] = {
    {
        .bus_num = I2C_MASTER_NUM,
        .conf = {
            .mode = I2C_MODE_MASTER,
            .sda_io_num = 21,
            .scl_io_num = 22,
            .sda_pullup_en = GPIO_PULLUP_ENABLE,
            .scl_pullup_en = GPIO_PULLUP_ENABLE,
            .master.clk_speed = 100000,
        },
        .tx_buf_len = I2C_MASTER_TX_BUF_DISABLE,
        .rx_buf_len = I2C_MASTER_RX_BUF_DISABLE,
    },
    {.bus_num = I2C_NONE},
};
#ifdef ESP32
int I2cMasterInit()
{
    esp_err_t ret = 0;
    struct i2c_client *client;
    for(int i = 0; i < MAX_BUS_NUM; i++)
    {
        if(i2c_client_array[i].bus_num == I2C_NONE)
            break;
        client = &i2c_client_array[i];
        i2c_param_config(client[i].bus_num, &client[i].conf);
        ret =  i2c_driver_install(client[i].bus_num, client[i].conf.mode, client[i].tx_buf_len, client[i].rx_buf_len, 0);  
        if(ret != ESP_OK)
            return ret;
        client[i].is_init = 1;
    }
    return ESP_OK;
}
#else
int I2cMasterInit()
{


}

#endif